// Fingerprint generation function
export function generateFingerprint() {
  return new Promise((resolve) => {
    // Try to use canvas fingerprinting
    try {
      const canvas = document.createElement('canvas');
      const ctx = canvas.getContext('2d');
      canvas.width = 200;
      canvas.height = 50;
      
      // Draw some text with various properties
      ctx.textBaseline = 'top';
      ctx.font = "14px 'Arial'";
      ctx.textBaseline = 'alphabetic';
      ctx.fillStyle = '#f60';
      ctx.fillRect(125, 1, 62, 20);
      ctx.fillStyle = '#069';
      ctx.fillText('Hello, world! 🌍', 2, 15);
      ctx.fillStyle = 'rgba(102, 204, 0, 0.7)';
      ctx.fillText('Hello, world! 🌍', 4, 17);
      
      const canvasData = canvas.toDataURL();
      
      // Combine with other browser characteristics
      const fingerprintData = [
        navigator.userAgent,
        navigator.language,
        screen.colorDepth,
        screen.pixelDepth,
        new Date().getTimezoneOffset(),
        !!window.indexedDB,
        !!window.DeviceMotionEvent,
        typeof navigator.maxTouchPoints !== 'undefined' ? navigator.maxTouchPoints : 0,
        canvasData
      ].join(';;');
      
      // Simple hash function
      let hash = 0;
      for (let i = 0; i < fingerprintData.length; i++) {
        const char = fingerprintData.charCodeAt(i);
        hash = ((hash << 5) - hash) + char;
        hash = hash & hash; // Convert to 32bit integer
      }
      
      resolve(Math.abs(hash).toString());
    } catch (e) {
      // Fallback fingerprint using simpler properties
      const fallbackData = [
        navigator.userAgent,
        navigator.platform,
        navigator.language,
        screen.width,
        screen.height,
        screen.colorDepth,
        new Date().getTimezoneOffset()
      ].join(';;');
      
      // Simple hash function
      let hash = 0;
      for (let i = 0; i < fallbackData.length; i++) {
        const char = fallbackData.charCodeAt(i);
        hash = ((hash << 5) - hash) + char;
        hash = hash & hash; // Convert to 32bit integer
      }
      
      resolve(Math.abs(hash).toString());
    }
  });
}